<?php
namespace app\common\model\shop\ozon;

use app\common\model\admin\AccountModel;
use app\common\model\shop\ShopsModel;
use think\admin\Model;

/**
 * OzonGoodsSkuStockModel
 * @Description
 * @package app\common\model\shop\ozon
 * @author wangqinghui
 * @date 2024-12-23 17:40
 */
class OzonGoodsSkuStockModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'shop_goods_sku_stock_ozon';

    // 自动写入时间戳
    protected $autoWriteTimestamp = false;

    /**
     * 日志名称
     * @var string
     */
    protected $oplogName = 'ozon商品SKU库存';

    /**
     * 日志类型
     * @var string
     */
    protected $oplogType = 'ozon商品SKU库存管理';

    /**
     * 获取推送状态
     * @Description
     * @author wangqinghui
     * @date 2024-12-26 11:29
     * @return array
     */
    public static function getPushStatusArr(): array
    {
        return [ 0 => lang('未推送'), 1 => lang('已推送'), 2 => lang('已同步')];
    }

    /**
     * 关联仓库
     * @Description
     * @author wangqinghui
     * @date 2024-12-30 11:39
     * @return \think\model\relation\BelongsTo
     */
    public function warehouse(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(OzonWarehouseModel::class, 'warehouse_id', 'warehouse_id')->bind(['warehouse_name' => 'name']);
    }

    /**
     * 关联商品
     * @Description
     * @author wangqinghui
     * @date 2024-12-30 11:40
     * @return \think\model\relation\BelongsTo
     */
    public function goods(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(OzonGoodsModel::class, 'goods_id', 'id')->bind(['spu_code', 'spu_name' => 'title']);
    }

    /**
     * 关联公司
     * @Description
     * @author wangqinghui
     * @date 2024-12-30 14:22
     * @return \think\model\relation\BelongsTo
     */
    public function account(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(AccountModel::class, 'account_id', 'id')->bind(['account_name' => 'title']);
    }

    /**
     * 关联店铺
     * @Description
     * @author wangqinghui
     * @date 2024-12-30 14:52
     * @return \think\model\relation\BelongsTo
     */
    public function shop(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(ShopsModel::class, 'shop_id', 'id')->bind(['shop_name' => 'name']);
    }
}